<template>
  <div class="pay">
    <my-header title="添加收货地址">
      <template #right>
        <slot name="right"> &nbsp; </slot>
      </template>
    </my-header>

    <div class="addwrap" ref="address">
      <van-address-edit
        :area-list="areaList"
        show-postal
        show-delete
        show-set-default
        show-search-result
        :search-result="searchResult"
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        @delete="onDelete"
      />
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
import { areaList } from "@vant/area-data";
export default {
  data() {
    return {
      areaList,
      searchResult: [],
    };
  },
  methods: {
    // 保存地址
    async onSave(value) {
      // console.log(value);
      let res = await this.$ajax.addDataToAddress({
        ...value,
        uid: this.userInfo.id,
      });
      console.log(res);
      if (res.length > 0) {
        Toast("添加成功");
      }
    },
    // 删除地址
    onDelete() {
      Toast("删除成功");
      // console.log(this.$refs.address);
    },
  },
  mounted() {},
};
</script>